<template>
	<view class="self_piece" >
		<view v-for="(item,index) in videolist"    :key="item._id" :data-uid="item._id">
			<my-piece  :item="item" @deletevideo="deletevideo"></my-piece>
		</view>
			<u-modal @cancel="cancel" @confirm="confirm" :showCancelButton="true" confirmText="确认删除" :show="immediate" :title="title" :content='content'></u-modal>
			<view class="nomore" v-if="nomore">
				<text>暂未发布</text>
			</view>
	</view>
</template>

<script>
	const db=uniCloud.database()
	export default {
		data() {
			return {
				title:"你将要删除",
				content:'',
				immediate:false,
			videolist:[],
			delete_id:"",
			nomore:false
			};
		},
		onLoad() {
			let user_id=uniCloud.getCurrentUserInfo().uid
			this.getvideo(user_id)
		},
		methods:{
			//确认删除
			confirm(){
				uni.showLoading({
					title:"删除中",
					mask:true
				})
				console.log(this.delete_id)
				console.log('删除成功',this.delete_id)
				db.collection("video-articles").where({
					'_id':this.delete_id
				}).remove().then(res=>{
					uni.hideLoading()
					this.getfilters()
					uni.showToast({
						title:"删除成功"
					})
				})
			this.immediate=false
			
			},
			//取消删除
			cancel(){
				
				this.immediate=false
			},
			
			deletevideo(e){
				this.immediate=true
				console.log(e,'eee')
				this.content=e[1]
				this.delete_id=e[0]
				console.log(e[0],'798')
			},
		changeshow(){
			
			console.log(this.isshow,"dfsad")
		},
		async getvideo(id) {
			let reTemp = db.collection("video-articles").where({
				"user_id": id,
		
			}).field(
				'user_id,publish_date,avatar,content,title'
			).getTemp()
		
			let userTemp = db.collection("uni-id-users").field('_id,nickname,avatar').getTemp()
			await db.collection(reTemp, userTemp).orderBy('publish_date desc').get().then(
				res => {
					if (res.result.data.length == 0) {
						this.nodata = true
					}
					console.log('不是广告', res)
					this.videolist = res.result.data
						
					if(res.result.data.length==0){
						this.nomore=true
					}
				})
		},
		getfilters(){
				console.log('执行了')
		this.videolist=	this.videolist.filter(item=>{
				return item._id!=this.delete_id
			})
		}
		}
	}
</script>

<style lang="scss" scoped>
	.self_piece{
		// height: 100vh;
		.nomore{
			height: 30vh;
			display: flex;
			justify-content: center;
			align-items: center;
			font-size: 60rpx;
			color: #F2E8CF;
		}
	}
</style>
<style>
	
	page{
		background-color: #10255b;
	}
	</style>